//使用express构建web服务器 --11:25
const express = require('express');
//const pool = require("pool");
const bodyParser = require('body-parser');
var app = express();
app.listen(5050);
//托管静态资源到public目录下
app.use(express.static('public'));
//使用body-parser中间件
app.use(bodyParser.urlencoded({extended:false}));


const index=require("./routes/index.route.js");
const discoverNews=require("./routes/discover.route.js");
const mark=require("./routes/mark.route.js");
const disforum=require("./routes/discover.forum.js");
const newsDetail=require("./routes/newsDetail.js");
const getComment=require("./routes/getComment.route.js"); 
const addComment=require("./routes/addComment.route.js");
const login=require("./routes/login.route.js");
const addCart=require("./routes/addcart.route.js");
const cartList=require("./routes/cartlist.route.js");



const carDetailImg=require("./routes/cardetail.carimgs.route.js");
const carDetailInfo=require("./routes/cardetail.type.route.js");

const queryCart=require("./routes/querycart.route.js");
const deleCarItem=require("./routes/deleCarItem.route.js");
const deleAllCarItem=require("./routes/deleAllCarItem.route.js");
const logout=require("./routes/logout.route.js");
const upload=require("./routes/upload.route.js");
const search=require("./routes/search.route.js");
const regs=require("./routes/regs.route.js");
const order=require("./routes/addDriveOder.route.js");
const seller=require("./routes/seller.route.js");
const findcar=require("./routes/findCar.route.js");
const videoDetail=require("./routes/videoDetail.route.js");

//解决跨越插件
var cors = require('cors');
app.use(cors({
  origin:[
    "http://127.0.0.1:8080",
    "http://localhost:8080",
    "http://localhost:8081",
    "http://127.0.0.1:8081",
    "http://192.168.1.108:8080",
    "http://192.168.1.108:8081",
    "http://localhost:5050"
  ],
  //origin:"*",
  credentials:true   //配置:允许客户端携带cookie
}));

//6.1:下载express-session并且配置
const session=require("express-session");
app.use(session({
  secret:"125位随机字符", //安全字符
  resave:false,          //每次请求是否更新数据
  saveUninitialized:true,     //初始化时是否保存数据
  cookie:{
    maxAge:1000*60*60*8
  }
}))

                       

       



/*使用路由器来管理路由*/
/**使用路由器来托管路由 */
//http://localhost:3000/index
app.use("/index",index);
app.use("/discoverNews",discoverNews);
app.use("/disforum",disforum);
app.use("/mark",mark);
app.use("/newsDetail",newsDetail); 
app.use("/getComment",getComment);
app.use("/addComment",addComment);
//app.use("/gettext",gettext);
app.use("/login",login);
app.use("/regs",regs);
app.use("/carDetailInfo",carDetailInfo);
app.use("/carDetailImg",carDetailImg);
app.use("/addCart",addCart);
app.use("/queryCart",queryCart);
app.use("/cartList",cartList);
app.use("/deleCarItem",deleCarItem);
app.use("/deleAllCarItem",deleAllCarItem);
app.use("/logout",logout);
app.use("/upload",upload);
app.use("/search",search);
app.use("/order",order);
app.use("/seller",seller);
app.use("/findcar",findcar);
app.use("/videoDetail",videoDetail);
